
//
//  MemLibraryDetailController.m
//  PASystem
//
//  Created by 刘沿 on 16/9/9.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "MemLibraryDetailController.h"
#import "MemberDetailModel.h"

@interface MemLibraryDetailController ()

@property (nonatomic,strong) NSMutableArray *dataArray;


@end

@implementation MemLibraryDetailController

-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        
        _dataArray = [NSMutableArray array];
    }

    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData];
}

- (void)loadData{
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString *json = [NSString stringWithFormat:@"{'action': wykMch,'service': LibrarieService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.ID];
    
    NSArray * array = @[@{@"arg0":json}];
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
        [self.dataArray removeAllObjects];
       
        NSDictionary *dict = JSON[@"reason"];
        
        NSDictionary *dict2 = dict[@"attrs"];
        
        MemberDetailModel *model = [MemberDetailModel mj_objectWithKeyValues:dict2];
        
        [self.dataArray addObject:model];
        
        [self.tableView headerEndRefreshing];
        
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];


}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 7;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MemberDetailModel *model = self.dataArray.firstObject;
    if (indexPath.row == 0) {
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10,80, 40)];
        
        label.text = @"委员名称:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        
        lbl2.text = model.NAME;
        
        lbl2.textAlignment = NSTextAlignmentRight;
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        
        return cell;
        
    }else if (indexPath.row == 1){
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 80, 40)];
        
        label.text = @"所在单位:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        lbl2.textAlignment = NSTextAlignmentRight;
        
        lbl2.text = model.COMPANY;
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        return cell;
        
    }
    else if (indexPath.row == 2){
        
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 80, 40)];
        
        label.text = @"联系方式:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.TEL;
        lbl2.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        
        return cell;
        
        
    }
    else if (indexPath.row == 3){
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10,40, 40)];
        
        label.text = @"职务:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.DUTIES;
        lbl2.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        
        return cell;
        
    }
    else if (indexPath.row == 4){
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
        
        label.text = @"地址:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.ADDRESS;
        lbl2.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        
        return cell;
    }
    else if (indexPath.row == 5){
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
        
        label.text = @"邮编:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.CODE;
        lbl2.font = [UIFont systemFontOfSize:15];
        
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        return cell;
        
    }
    else if (indexPath.row == 6){
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 80, 40)];
        
        label.text = @"所属区域:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.AREA;
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        
        return cell;
        
    }else{
    
        return nil;
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 60;
}


@end

































